home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Tool Chest / Interapplication Communication / AE Tools / AE Builder⁄Printer Library 1.1 / Demo MPW Tool / AEBuildDemo.c next >
Encoding:
C/C++ Source or Header  |  1992-02-19  |  2.3 KB  |  99 lines  |  [TEXT/MPS ]

  1. /*
  2.  *    AppleEvent Builder test tool
  3.  *    by Jens Peter Alfke
  4.  *
  5.  *    How it works: Each argument will be sent to AEBuild, then AEPrint, and the end
  6.  *    result printed. It reports syntax errors in a semi-human-readable fashion.
  7.  *    If there are no arguments it asks for a line of input from the user.
  8.  *
  9.  *  NOTE: This code was written in MPW C.
  10.  *
  11.  *    Copyright ©1991 Apple Computer, Inc. All rights reserved.
  12.  *
  13.  *    APPLE CONFIDENTIAL
  14.  */
  15.  
  16. #include <stdio.h>
  17. #include <AppleEvents.h>
  18. #include "sneJ:Work:AEBuilder:AEBuild.h"
  19. #include "sneJ:Work:AEBuilder:AEBuildGlobals.h"
  20. #include "sneJ:Work:AEBuilder:AEPrint.h"
  21.  
  22.  
  23. char *AEBuild_ErrMsgs[] = {
  24.     "[No Error!]",
  25.     "Illegal character",
  26.     "Unexpectedly fell off end of line",
  27.     "Extra stuff past end of descriptor",
  28.     "“-” not followed by a number",
  29.     "Missing close “'”",
  30.     "Illegal digit in hex string",
  31.     "Hex string has an odd number of digits",
  32.     "Missing “»”",
  33.     "Hex string must be coerced to some data type",
  34.     "Missing “””",
  35.     "Illegal descriptor",
  36.     "Illegal data value inside parentheses",
  37.     "Expected “)” after data value",
  38.     "Expected “]” or “,” after a list item",
  39.     "Expected “}” or “,” after a record item",
  40.     "Expected a record keyword",
  41.     "Missing “:” after record keyword"
  42. };
  43.  
  44.  
  45. int main( int argc, char *argv[] );
  46.  
  47.  
  48. int
  49. main( int argc, char *argv[] )
  50. {
  51.     int i;
  52.     OSErr err;
  53.     AEDesc desc;
  54.     char *str, strbuf[1024];
  55.         
  56.     for( i=1; i<argc || i==1; i++ ) {
  57.         if( i>1 )
  58.             printf("#\n");
  59.         else
  60.             printf("### AEBuildDemo:\n");
  61.         
  62.         printf("# Input:  ");
  63.         if( i<argc )
  64.             puts( str = argv[i] );
  65.         else {
  66.             puts("[Please enter a descriptor string and press Enter:]");
  67.             gets(strbuf);
  68.             str = strbuf;
  69.         }
  70.         err= AEBuild(&desc, str);
  71.         if( err ) {
  72.             long j;
  73.             
  74.             if( i<argc )
  75.                 printf("#         ");
  76.             for( j=1; j<AEBuild_ErrPos; j++ )
  77.                 putchar(' ');
  78.             printf("^\n#    ");
  79.             if( err==aeBuild_SyntaxErr )
  80.                 printf("Syntax error: %s\n", AEBuild_ErrMsgs[AEBuild_ErrCode]);
  81.             else
  82.                 printf("**Error %d in AEBuild**\n",err);
  83.         } else {
  84.             sprintf(strbuf, "Built '%.4s' desc at %p, %d bytes of data at %p",
  85.                                 &desc.descriptorType, &desc,
  86.                                 GetHandleSize(desc.dataHandle), &(**desc.dataHandle));
  87.             debugstr(strbuf);
  88.  
  89.             printf("# Output: ");
  90.             err= AEPrint(&desc, strbuf,sizeof(strbuf));
  91.             if( err )
  92.                 printf("**Error %d in AEPrint**\n", err);
  93.             else
  94.                 puts(strbuf);
  95.         }
  96.     }
  97.     return 0;
  98. }
  99.